
$("#loginBtn").click(function () {
    console.log("click");
    var userName = document.getElementById("user_account").value;
    var userPwd = document.getElementById("userPwd").value;
    rawData = { "useraccount": userName, "userPwd": userPwd };
    $.ajax({
        url: '/login',
        type: 'post',
        data: rawData,
        success: function (data, status) {
            if (status == 'success') {
                window.location.href = '/index.html';
            }
        },
        error: function (data, status) {
            if (status == 'error') {
                alert("登录失败！");
            }
        }
    });
});

$("#doRegister").click(function () {
    //userAccount：手机号
    var userAccount = $('#n_user_account').val();
    //验证码
    var verificationCode = $('#verificationCode').val();
    //真实姓名
    var userName = $('#n_user_name').val();
    //密码
    var userPwd_1 = $('#u_user_pwd_1').val();
    //重复密码
    var userPwd_2 = $('#u_user_pwd_2').val();
    if (userPwd_1 == userPwd_2){
        rawData = { "userName": userName, "userPwd": userPwd_1, "userAccount": userAccount };
        console.log(rawData);
        $.ajax({
            url:'/register',
            type:'post',
            data: rawData,
            success:function (data,status) {
                if (status == 'success') {
                    alert("注册成功");
                    window.location.href = '/login';
                }
            },
            error:function (data,status) {
                if (status == 'error') {
                    alert("注册失败！");
                }
            }

        })
    }else {
        alert('两次输入的密码必须一致');
    }
});

function getVerificationCode(obj) {
    var phoneNum = $('#n_user_account').val();
    if (obj.id == 'reset'){
        console.log(obj.id);
        document.getElementById('yanzhengma_div').style.display = 'inline';
    }else if (obj.id == 'register'){
        document.getElementById('hide_div').style.display = 'inline';
        $.ajax({
            url: '/getCode',
            type: 'post',
            data: {'inputPhone': phoneNum},//这里应该保存手机号
            success: function (data, status) {
                if (status == 'success') {
                    console.log("啊doLogin");
                }
            },
            error: function (data, status) {
                if (status == 'error') {
                    alert("登录失败！");
                }
            }
        });
    }
}
